﻿using System;
using System.Collections.Generic;
using MdcService.Static;
using MdcService.Structure;

namespace MdcService.DataAccess
{
    public class MemoryDataAccess:IRealTimeDataAccess<MachineValue>,IHistoryDataAccess<MachineValue> 
    {
        private readonly Dictionary<string,MachineValue> _data = new Dictionary<string, MachineValue>();

        public IEnumerable<MachineValue> Data { get; set; }

        public void Insert(MachineValue value)
        {
            _data[value.Id] = value;
        }

        public void Insert(IEnumerable<MachineValue> values)
        {
            values.ForEach(Insert);
        }

        public List<MachineValue> Select(string command)
        {
            var x = _data.ContainsKey(command) ? new List<MachineValue> { _data[command] } : new List<MachineValue>();
            return x;
        }

        public void Update(IEnumerable<MachineValue> values)
        {
            Insert(values);
        }

        public void Update(MachineValue value)
        {
            throw new NotImplementedException();
        }

        public void Delete(IEnumerable<MachineValue> values)
        {
            values.ForEach(i =>
            {
                if (_data.ContainsKey(i.Id))
                {
                    _data.Remove(i.Id);
                }
            });
        }

        public void Delete(MachineValue value)
        {
            throw new NotImplementedException();
        }

    }
}
